package com.coffee.system.controller;

import com.coffee.framework.common.exception.CustomException;
import com.coffee.framework.common.minio.MinioUtil;
import com.coffee.framework.common.result.R;
import com.coffee.framework.common.result.ResultCode;
import com.coffee.framework.log.annotation.AutoLog;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;


/**
 * <p>
 * 通用common 前端控制器
 * </p>
 *
 * @author Kevin
 */
@RestController
@RequestMapping("/system/common")
@Slf4j
@AllArgsConstructor
public class SysCommonController {

    private MinioUtil minioUtil;

    @SneakyThrows
    @PostMapping("/upload")
    @AutoLog(module = "通用模块", title = "上传文件")
    public R<String> upload(MultipartFile file, @RequestParam String bizPath) {
        if (Objects.isNull(file)) {
            throw new CustomException(ResultCode.PARAM_MISS.getMessage());
        }
        String url = minioUtil.upload(file, bizPath);
        return R.success(url);
    }

}
